﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">类型编码</label>
                <div class="layui-input-inline">
                    <input type="text" name="toolTypeCode" lay-verify="required" placeholder="请输入库位编号" autocomplete="off" class="layui-input" id="toolTypeCode">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">自动生成</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="switch" lay-skin="switch" lay-text="OFF|ON" lay-filter="switchFilter">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">类型名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="toolTypeName" lay-verify="required" placeholder="请输入库位名称" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width:auto">是否单独编码管理</label>
                <div class="layui-input-inline" style="width: 180px;">
                    <input type="radio" name="codeFlag" value="Y" title="是" checked>
                    <input type="radio" name="codeFlag" value="N" title="否">
                </div>
                <label class="layui-form-label" style="width:auto">保养维护类型</label>
                <div class="layui-input-inline">
                    <select name="maintenType" lay-filter="aihao">
                        <option value="" selected></option>
                        <option value="定期维护">定期维护</option>
                        <option value="按使用次数维护">按使用次数维护</option>
                    </select>
                </div>
                <label class="layui-form-label">保养周期</label>
                <div class="layui-input-inline">
                    <input type="text" name="maintenPeriod" lay-verify="required" placeholder="请输入保养周期" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>

    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;

            // 自动生成仓库编号
            form.on('switch(switchFilter)', function (data) {
                if (data.elem.checked) {
                    var date = new Date(); // 获取当前日期
                    var year = date.getFullYear(); // 获取当前年份
                    //获取时间戳
                    var num = date.getTime();
                    //根据时间戳生成6位随机数
                    num = num.toString().substr(num.toString().length - 6);
                    num = num.toString().padStart(6, '0'); //前面补零
                    document.getElementById('toolTypeCode').value = year + '' + num;
                } else {
                    document.getElementById('toolTypeCode').value = '';
                }
            });

            // 提交事件
            form.on('submit(demo1)', function (data) {
                var field = data.field;
                $.get('/Zhou/AddToolType', field, function (res) {
                    if (res > 0) {
                        layer.msg('保存成功', {
                            icon: 1,
                            time: 500
                        }, function () {
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index);//再执行关闭
                        });
                    } else {
                        layer.msg("网络异常");
                    }
                });
                return false; // 阻止默认 form 跳转
            });

        });
    </script>

</body>
</html>